package servlet.rest;

import service.CskaoyanSqlSessionFactory;
import bean.model.Log;
import mapper.LogMapper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/")
public class Rest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //这里的接口都是没有接口匹配到的接口
        SqlSession sqlSession= CskaoyanSqlSessionFactory.sqlSessionFactory.openSession();
        Log log=new Log();
        log.setOperation(req.getRequestURI());
        log.setIp(req.getRemoteAddr());
        log.setAddTime(new Date());
        log.setSuccess(1);

        LogMapper logMapper=sqlSession.getMapper(LogMapper.class);

        int result=logMapper.addLog(log);
        sqlSession.commit();
        resp.getWriter().println(404);

    }
}
